/*
 * @Author: szx
 * @Date: 2022-06-22 18:42:21
 * @LastEditTime: 2022-06-22 18:47:36
 * @Description:
 * @FilePath: \leetcode\面试题\17\12\12.js
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var convertBiNode = function (root) {
    let prev = null;
    const head = null;
    const dfs = (root) => {
        if (!root) return;
        dfs(root.left);
        if (prev === null) {
            prev = root;
            head = root;
        } else {
            prev.right = root;
            prev.left = null;
            prev = root;
        }
        dfs(root.right);
    };
    dfs(root);
    return head;
};
